import { getToken, setToken, delToken } from '@/utils/storage'
import { login } from '@/api/user'
export default {
  state () {
    return {
      token: getToken()
    }
  },
  mutations: {
    setUserToken (state, payload) {
      state.token = payload
      setToken(payload)
    },
    reseToken (state) {
      state.token = null
      delToken()
    }
  },
  actions: {
    async loginAction (context, payload) {
      const res = await login(payload)
      console.log(res);
      context.commit('setUserToken', res.data.token)
    }
  },
  getters: {},
  namespaced: true
}